using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SilkSharp
{
	public class Silk_SigProc_FLP_constants
	{
		/* Pitch estimator */
		public const int SigProc_PITCH_EST_MIN_COMPLEX = 0;
		public const int SigProc_PITCH_EST_MID_COMPLEX = 1;
		public const int SigProc_PITCH_EST_MAX_COMPLEX = 2;

		public const float PI = 3.1415926536f;
	}

	public class Silk_SigProc_FLP : Silk_SigProc_FLP_constants
	{
		public static float SKP_min_float( float a, float b )
		{
			return ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) );
		}
		public static float SKP_max_float( float a, float b )
		{
			return ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) );
		}
		public static float SKP_abs_float( float a )
		{
			return Math.Abs( a );
		}

		public static float SKP_LIMIT_float( float a, float limit1, float limit2 )
		{
			if( limit1 > limit2 )
				return a > limit1 ? limit1 : ( a < limit2 ? limit2 : a );
			else
				return a > limit2 ? limit2 : ( a < limit1 ? limit1 : a );
		}

		/* sigmoid function */
		public static float SKP_sigmoid( float x )
		{
			return (float)( 1.0 / ( 1.0 + Math.Exp( -x ) ) );
		}

		/* floating-point to integer conversion (rounding) */
		public static void SKP_float2short_array
		(
			short[] _out,
			int out_offset,
			float[] _in,
			int in_offset,
			int length
		)
		{
			int k;
			for( k = length - 1; k >= 0; k-- )
			{
				double x = _in[ in_offset + k ];
				_out[ out_offset + k ] = (short)Silk_SigProc_FIX.SKP_SAT16( (int)( ( x > 0 ) ? x + 0.5 : x - 0.5 ) );
			}
		}

		/* floating-point to integer conversion (rounding) */
		public static int SKP_float2int( double x )
		{
			return (int)( ( x > 0 ) ? x + 0.5 : x - 0.5 );
		}

		/* integer to floating-point conversion */
		public static void SKP_short2float_array
		(
			float[] _out,
			int out_offset,
			short[] _in,
			int in_offset,
			int length
		)
		{
			int k;
			for( k = length - 1; k >= 0; k-- )
			{
				_out[ out_offset + k ] = (float)_in[ in_offset + k ];
			}
		}

		//TODO:	#define SKP_round(x)		(SKP_float)((x)>=0 ? (SKP_int64)((x)+0.5) : (SKP_int64)((x)-0.5))
		public static float SKP_round( float x )
		{
			return (float)( ( x ) >= 0 ? (long)( x + 0.5 ) : (long)( x - 0.5 ) );
		}
	}
}
